
<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>


<div class="panel ">
	<div class="panel-body pan" style="height: 485px">
		<form action="#" class="form-horizontal">
			<div class="form-body pal">
				<div class="row" style="margin-top:-15px; margin-bottom: 10px;">
					<div class="col-lg-6"
						style="width: 400px; float:left;  margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">用户名
							<span class='require' id="yonghu">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="username" onchange="onPanduan(this.value);"
									type="text" class="form-control" value="" />
							</div>
						</div>
					</div>
					<div class="col-lg-6"
						style="width: 400px; float:right; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">密码
							<span class='require' id="mima">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="password" type="password" class="form-control" />
							</div>
						</div>
					</div>
				</div>
				<div class="row" style="margin-bottom: 10px;">
					<div class="col-lg-6"
						style="width: 400px; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">昵称
							<span class='require' id="yonghu">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="nickname"
									type="text" class="form-control" value="" />
							</div>
						</div>
					</div>
					<div class="col-lg-6"
						style="width: 400px; float:right; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">手机号
							<span class='require' >*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="telephone" type="text" class="form-control" />
							</div>
						</div>
					</div>
				</div>
				<div class="row" style="margin-bottom: 10px;">
					<div class="col-lg-6"
						style="width: 400px; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">地址
							<span class='require' id="yonghu">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="address"
									type="text" class="form-control" value="" />
							</div>
						</div>
					</div>
					<div class="col-lg-6"
						style="width: 400px; float:right; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">邮箱
							<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="email" type="text" class="form-control" />
							</div>
						</div>
					</div>
				</div> 	
				<div class="row" style="margin-bottom: 10px;">
					<div class="col-lg-6"
						style="width: 400px; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">部门名称<span
						class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-group input-group-sm mbs">
								<input id="parentclassname" type="text" placeholder="请选择部门" class="form-control" disabled="true" /> 
								<span class="input-group-btn">
								<button id="xuanze" onclick="saveclassZTree()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
								</span> 
								<input id="parentClassid" type="hidden" value="00" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-lg-6"
						style="width: 400px; float:right; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">创建日期
							<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="createTime" disabled="disabled" type="text" class="form-control" />
							</div>
						</div>
					</div>
				</div> 
				<div id="userGroup" class="row" style="margin-bottom: 10px;">
					<div class="col-lg-6"
						style="width: 400px; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">用户组名称<span
						class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-group input-group-sm mbs">
								<input id="userGroupName" type="text" placeholder="请选择用户组" class="form-control" disabled="true" /> 
								<span class="input-group-btn">
								<button id="xuanze2" onclick="saveGroupZTree()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
								</span> 
								<input id="userGroupId" type="hidden" value="00" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-lg-6" style="width: 400px; float:right; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">是否部门负责人
						<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<select id="status" class="form-control">
									<option value="0">否</option>
									<option value="1">是</option>
								</select>
							</div>
						</div>
					</div>
					
				</div> 
				<div>
					<label for="inputUsername" class="col-md-3 control-label">个性签名
						<span class='require'></span> </label>
					<div class="col-md-12">
						<div class="input-icon">
							<textarea id="signature"  rows="3" cols="20" class="form-control" ></textarea> 
						</div>
					</div>
				</div>
				<input id="id" type="hidden" class="form-control" />
		</form>
	</div>
</div>
<?} ?>
<script>
	var index1 = window.parent.getlay();
	$(function() {
		if (index1 != 0) {
			$("#username").attr("disabled", "true");
			$("#mima").html("");
			demo1();
		} else if(index1 ==0){
			newdate();
		}
	});
	
	function Page() {
		if ($.trim($("#username").val()).length < 1) {
			alert('用户名不能为空！');
			return null;
		}
		if (index1 == 0) {
			if ($.trim($("#password").val()).length < 1) {
				alert('密码不能为空！');
				return null;
			}
		}
		if ($.trim($("#nickname").val()).length < 1) {
			alert('昵称不能为空！');
			return null;
		}
		var telephonetext=$.trim($("#telephone").val()); //    
       	var telephonere =/^[0-9]{11}$/;
		if (!telephonere.test(telephonetext)) {
			alert('手机号格式不正确！');
			return null;
		}
		if ($.trim($("#address").val()).length < 1) {
			alert('地址不能为空！');
			return null;
		}
	   	var text=$.trim($("#email").val()); //    
       	var re =/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
		if (!re.test(text)) {
			alert('邮箱格式不正确！');
			return null;
		}
		if ($.trim($("#parentClassid").val()).length < 1 || $("#parentClassid").val()==0) {
			alert('请选择部门！');
			return null;
		} 	
		if ($.trim($("#userGroupId").val()).length < 1 || $("#userGroupId").val()==0) {
			alert('请选择用户组！');
			return null;
		} 

		$.ajax({
			type : "post",
			url : "./userAddandUpdate.do",
			data : {
				"id" : index1,
				"username" : $("#username").val(),
				"password" : $("#password").val(),
				"nickname" : $("#nickname").val(),
				"telephone" : $("#telephone").val(),
				"address" : $("#address").val(),
				"email" : $("#email").val(),
				"departmentId" : $("#parentClassid").val(),
				"createTime" : $("#createTime").val(),
				"userPid" : $("#userPid").val(),
				"signature" : $("#signature").val(),
				"userGroupId" : $("#userGroupId").val(),
				"status" : $("#status").val(),
			},
			dataType : "json",
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.get();
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	function demo1() {
		$.getJSON('./userfindone.do', {
			id : index1
		//向服务端传的参数，此处只是演示
		}, function(res) {
			//此处仅仅是为了演示变化的内容
			$("#username").val(res[0].username);
			$("#nickname").val(res[0].nickname);
			$("#telephone").val(res[0].telephone);
			$("#address").val(res[0].address);
			$("#email").val(res[0].email);
			$("#parentclassname").val(res[0].departmentName);
			$("#parentClassid").val(res[0].departmentId);
			$("#createTime").val(res[0].createTime);
			$("#signature").val(res[0].signature);
			$("#userGroupName").val(res[0].userGroupName);
			$("#userGroupId").val(res[0].userGroupId);
			$("#status").val(res[0].status);
		});
	};
	function newdate() {
		$.getJSON('./newDate.do', {},
				function(res) {
					$("#createTime").val(res.date);
				});
	};
	function onPanduan(name) {
		$.ajax({
			type : "post",
			url : "./UserPanDuan.do",
			data : {
				"username" : name
			},
			dataType : "json",
			async : false,
			success : function(data) {
				if (data[0].tishi == 0) {
					alert("用户名不能重复");
					$("#username").val("");
				}
			}
		});
	}
	//选择父类
	function saveclassZTree() {
		layer.open({
			type : 2,
			area : [ '360px', '400px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			title:"部门选择",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["user-editSave-department-zTree.html", 'no'],
			yes : function(index,layer) {		
			  var iframeWin = parent.window[window.name].window[layer.find('iframe')[0]['name']];
			  			  iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	function saveGroupZTree() {
		layer.open({
			type : 2,
			area : [ '360px', '400px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			title:"用户组选择",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["user-editSave-userGroup-zTree.html", 'no'],
			yes : function(index,layer) {		
			  var iframeWin = parent.window[window.name].window[layer.find('iframe')[0]['name']];
			  			  iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
</script>


